//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.middlegroup.subjectpay.service.ucfpay;

import java.io.IOException;
import java.security.GeneralSecurityException;
import java.util.Map;

public class UcfForOnline {
    public UcfForOnline() {
    }

    public static Boolean verify(String signKey, String signName, String sign, Map<String, String> params, String type) throws GeneralSecurityException, CoderException {
        boolean isVerifySuccess = false;
        if(null != sign && !"".equals(sign) && null != signKey && !"".equals(signKey)) {
            String e;
            if("MD5".equals(type)) {
                e = UcfDigestUtils.encode(signKey, UcfDigestUtils.getSignData(signName, params), type);
                if(sign.equals(e)) {
                    isVerifySuccess = true;
                }
            } else if("RSA".equals(type)) {
                try {
                    e = RsaCoder.decryptByPublicKey(sign, signKey);
                    String mySign = UcfDigestUtils.digestMD5(UcfDigestUtils.getSignData(signName, params)).toLowerCase();
                    isVerifySuccess = e.equals(mySign);
                } catch (Exception var8) {
                    isVerifySuccess = false;
                    throw new RuntimeException(var8);
                }
            }

            return Boolean.valueOf(isVerifySuccess);
        } else {
            return Boolean.valueOf(isVerifySuccess);
        }
    }

    public static String createSign(String signKey, String signName, Map<String, String> params, String type) throws GeneralSecurityException, CoderException {
        if("MD5".equals(type)) {
            return UcfDigestUtils.encode(signKey, UcfDigestUtils.getSignData(signName, params), type);
        } else if("RSA".equals(type)) {
            try {
                return RsaCoder.encryptByPublicKey(UcfDigestUtils.digestMD5(UcfDigestUtils.getSignData(signName, params)).toLowerCase(), signKey);
            } catch (Exception var5) {
                throw new RuntimeException(var5);
            }
        } else {
            return "";
        }
    }

    public static String encode(String data, String key, String codeType) throws GeneralSecurityException, CoderException {
        return UcfDigestUtils.encode(key, data, codeType);
    }

    public static String decode(String data, String key, String codeType) throws Exception {
        return UcfDigestUtils.decode(key, data, codeType);
    }

    public static String getX509Key(String x509FilePath) throws IllegalArgumentException, IOException {
        return CaUtils.getX509Key(x509FilePath);
    }
}
